﻿using BaseData.API.Write.Applications.HospitalInformation.Command;
using BaseData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BaseData.API.Write.Controllers.HospitalInformation
{
    /// <summary>
    /// 医院信息
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManageController : ControllerBase
    {
        IMediator mediator;
        ILogger<ManageController> logger;

        public ManageController(IMediator mediator, ILogger<ManageController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 科室管理添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns>返回影响行数</returns>
        [HttpPost]
        public async Task<ApiResult<int>> DepartmentsAdd(DepartmentsAddCommand request)
        {
            try
            {
                logger.LogInformation("添加成功");
                return await mediator.Send(request);
            }
            catch (Exception)
            {
                logger.LogError("添加失败");
                throw;
            }
        }
        /// <summary>
        /// 科室管理删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns>返回影响行数</returns>
        [HttpDelete]
        public async Task<ApiResult<int>> DepartmentsDel(DepartmentsDelCommand request)
        {
            try
            {
                logger.LogInformation("删除成功");
                return await mediator.Send(request);
            }
            catch (Exception)
            {
                logger.LogError("删除失败");
                throw;
            }
        }
        /// <summary>
        /// 科室管理修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns>返回影响行数</returns>
        [HttpPut]
        public async Task<ApiResult<int>> DepartmentsUpdate(DepartmentsUpdateCommand request)
        {
            try
            {
                logger.LogInformation("修改成功");
                return await mediator.Send(request);
            }
            catch (Exception)
            {
                logger.LogError("修改失败");
                throw;
            }
        }
        /// <summary>
        /// 医生管理添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns>返回影响行数</returns>
        [HttpPost]
        public async Task<ApiResult<int>> DoctorsAdd(DoctorsAddCommand request)
        {
            try
            {
                logger.LogInformation("添加成功");
                return await mediator.Send(request);
            }
            catch (Exception)
            {
                logger.LogError("添加失败");
                throw;
            }
        }
        /// <summary>
        /// 医院删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult<int>> DoctorsDelete(DoctorsDeleteCommand request)
        {
            try
            {
                logger.LogInformation("删除成功");
                return await mediator.Send(request);
            }
            catch (Exception)
            {
                logger.LogError("删除失败");
                throw;
            }
        }
        /// <summary>
        /// 医院修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DoctorsUpdate(DoctorsUpdateCommand request)
        {
            try
            {
                logger.LogInformation("修改成功");
                return await mediator.Send(request);
            }
            catch (Exception)
            {
                logger.LogError("修改失败");
                throw;
            }
        }
    }
}
